package com.gitee.controller;

import com.gitee.bo.FoodBo;
import com.gitee.enums.ResponseEnum;
import com.gitee.pojo.Food;
import com.gitee.service.IFoodService;
import com.gitee.vo.PageVo;
import com.gitee.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 菜品管理
 */
@RestController
@RequestMapping("/food")
public class FoodController {

    @Autowired
    private IFoodService foodService;

    /**
     * 菜品列表
     * @param keywords
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResponseVo<PageVo<Food>> list(String keywords, Integer pageNum, Integer pageSize) {
        PageVo<Food> foodPageVo = foodService.pageFoods(keywords, pageNum, pageSize);
        return ResponseVo.ok(foodPageVo);
    }

    /**
     * 添加菜品
     * @param foodBo
     * @return
     */
    @PostMapping
    public ResponseVo<String> add(@RequestBody FoodBo foodBo) {
        foodService.addFood(foodBo);
        return ResponseVo.ok(ResponseEnum.ADD_SUCCESS);
    }

    /**
     * 更新菜品
     * @param foodBo
     * @param foodId
     * @return
     */
    @PutMapping("/{foodId}")
    public ResponseVo<String> update(@RequestBody FoodBo foodBo, @PathVariable Integer foodId) {
        foodService.updateFood(foodBo, foodId);
        return ResponseVo.ok(ResponseEnum.UPDATE_SUCCESS);
    }

    /**
     * 删除菜品
     * @param foodId
     * @return
     */
    @DeleteMapping("/{foodId}")
    public ResponseVo<String> delete(@PathVariable Integer foodId) {
        foodService.deleteFood(foodId);
        return ResponseVo.ok(ResponseEnum.DELETE_SUCCESS);
    }

    /**
     * 批量删除菜品
     * @param foodIds
     * @return
     */
    @DeleteMapping("/batch")
    public ResponseVo<String> delete(@RequestBody Integer[] foodIds) {
        foodService.deleteFoodBatch(foodIds);
        return ResponseVo.ok(ResponseEnum.DELETE_SUCCESS);
    }
}
